package Org.lanqiao.team.service;

import Org.lanqiao.team.domain.*;

import static Org.lanqiao.team.service.Data.EMPLOYEES;
import static Org.lanqiao.team.service.Data.EQUIPMENTS;

public class NameListService {


    /**employees 用来保存公司所有员工对象
      NameListService()构造器：
      根据项目提供的 Data 类构建相应大小的 employees 数组
      再根据 Data 类中的数据构建不同的对象，包括 Employee、
     Programmer、Designer 和 Architect 对象，以及相关联的 Equipment
     子类的对象
      将对象存于数组中

     getAllEmployees ()方法：获取当前所有员工。
      返回：包含所有员工对象的数组
      getEmployee(id : int)方法：获取指定 ID 的员工对象。
      参数：指定员工的 ID
      返回：指定员工对象
      异常：找不到指定的员工
     */
    public Programmer[] programmers=new Programmer[EMPLOYEES.length];//团队成员
    public Designer[] designers=new Designer[EMPLOYEES.length];
    public Architect[] architects=new Architect[EMPLOYEES.length];
    private int total= 0;
    public  int ec=0;//employee count
    public  int pc=0;//programmer count
    public  int ac=0;//architect count
    public  int dc=0;//designer count
    public Employee[] employees=new Employee[EMPLOYEES.length];//employees 用来保存公司所有员工对象
    public NameListService(){

        Equipment equipment1 = null;
        Employee em=new Employee(Integer.parseInt(EMPLOYEES[0][1]), EMPLOYEES[0][2],
                Integer.parseInt(EMPLOYEES[0][3]),Integer.parseInt(EMPLOYEES[0][4]));
        employees[ec]=em;
        ec++;
        for (int i = 1; i < EQUIPMENTS.length; i++) {
            switch(EQUIPMENTS[i][0]){
                case "21":
                    equipment1 = new PC(EQUIPMENTS[i][1],EQUIPMENTS[i][2]);
                    break;
                case "22":
                    equipment1 = new NoteBook(EQUIPMENTS[i][1],Integer.parseInt(EQUIPMENTS[i][2]));
                    break;
                case "23":
                    equipment1 = new Printer(EQUIPMENTS[i][1],EQUIPMENTS[i][2]);
                    break;
            }
            switch(EMPLOYEES[i][0]){
                case "10":
                    Employee e=new Employee(Integer.parseInt(EMPLOYEES[i][1]), EMPLOYEES[i][2],
                            Integer.parseInt(EMPLOYEES[i][3]),Integer.parseInt(EMPLOYEES[i][4]));
                    employees[ec]=e;
                    ec++;
                    break;
                case "11":
                    Programmer p=new Programmer(Integer.parseInt(EMPLOYEES[i][1]), EMPLOYEES[i][2],
                            Integer.parseInt(EMPLOYEES[i][3]),Integer.parseInt(EMPLOYEES[i][4]),equipment1);
//                    if(pc==3)
//                        break;
                    programmers[pc]=p;
                    pc++;
                    break;
                case "12":
                    Designer d=new Designer(Integer.parseInt(EMPLOYEES[i][1]), EMPLOYEES[i][2],
                            Integer.parseInt(EMPLOYEES[i][3]),Integer.parseInt(EMPLOYEES[i][4]),
                            Integer.parseInt(EMPLOYEES[i][5]),equipment1);
//                    if(dc==2)
//                        break;
                    designers[dc]=d;
                    dc++;
                    break;
                case "13":
                    Architect a=new Architect(Integer.parseInt(EMPLOYEES[i][1]), EMPLOYEES[i][2],
                            Integer.parseInt(EMPLOYEES[i][3]),Integer.parseInt(EMPLOYEES[i][4]),
                            Integer.parseInt(EMPLOYEES[i][5]),Integer.parseInt(EMPLOYEES[i][6]),equipment1);
/*                    if(ac==1)
                        break;*/
                    architects[ac]=a;
                    ac++;
                    break;
            }
        }
    }
    public void getAllEmployees(){
        for (int i = 0; i < ec; i++)
            if(employees[i].getId()!=0)
                System.out.println(employees[i].toString());
        for (int i = 0; i < pc; i++)
            if(programmers[i].getId()!=0)
                System.out.println(programmers[i].toString());
        for (int i = 0; i < dc; i++)
            if(designers[i].getId()!=0)
                System.out.println(designers[i].toString());
        for (int i = 0; i < ac; i++)
            if(architects[i].getId()!=0)
                System.out.println(architects[i].toString());

    }
    public Employee getEmployee(int id){
        for (int i = 0; i < ec; i++)
            if(employees[i].getId()==id){
                return employees[i];
            }
        for (int i = 0; i < pc; i++){
            if(programmers[i].getId()==id){
                Employee employee=programmers[i];
                return employee;
            }
        }
        for (int i = 0; i < dc; i++){
            if(designers[i].getId()==id){
                Employee employee=designers[i];
                return employee;
            }
        }
        for (int i = 0; i < ac; i++){
            if(architects[i].getId()==id){
                Employee employee=architects[i];
                return employee;
            }
        }
        TeamException teamException=new TeamException("找不到指定的员工");
        return null;
    }
}
